package com.fr.lintcode;

import org.junit.Test;

/**
 * @author 付荣
 * @version 创建时间：2018年11月13日 下午8:01:21
 */
public class Q1023 {
	/**
     * @param K: an integer
     * @return: how many non-negative integers x have the property that f(x) = K
     */
    public int preimageSizeFZF(int K) {
    	long left = 0;
    	long right = 5 * (K + 1L);
        while(left <= right){
        	long mid = (left + right) / 2;
        	long sum = getZeroNum(mid);
        	if(sum == K) {
        		return 5;
        	}else if(sum > K) {
        		right = mid - 1;
        	}else {
        		left = mid + 1;
        	}
        }
        return 0;
    }
    
    long getZeroNum(long j) {
    	long sum = 0;
    	while(j > 0){
			sum = sum + (j/5);
			j= j/5 ;
		}
    	return sum;
    }
    
    @Test
    public void testA(){
    	System.out.println(preimageSizeFZF(1000000000));
    }
}
